package uni.UNIBEE7B8D.view.Study.ZhiboContent;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import uni.UNIBEE7B8D.Adapter.NewsFragmentAdapter;
import uni.UNIBEE7B8D.Adapter.zhibo.ZhiboKejianAdapter;
import uni.UNIBEE7B8D.BaseActivity;
import uni.UNIBEE7B8D.Enty.ClassCon;
import uni.UNIBEE7B8D.Enty.CommonClass;
import uni.UNIBEE7B8D.Enty.KechengCon;
import uni.UNIBEE7B8D.Enty.ZhiboContent;
import uni.UNIBEE7B8D.Presenter.ZhiboConPersenter;
import uni.UNIBEE7B8D.R;

public class ZhiboContentActivity extends BaseActivity implements ZhiboContentContract.ZhiboConView {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.headTitle)
    TextView headTitle;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.player)
    StandardGSYVideoPlayer player;
    @BindView(R.id.kejianList)
    RecyclerView kejianList;
    @BindView(R.id.pst)
    TabLayout pst;
    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.cost)
    TextView cost;
    @BindView(R.id.memberCost)
    TextView memberCost;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.zhibo_title)
    TextView zhibo_title;
    @BindView(R.id.memberCost1)
    TextView memberCost1;
    @BindView(R.id.view2)
    LinearLayout view2;
    @BindView(R.id.view3)
    LinearLayout view3;
    @BindView(R.id.view4)
    LinearLayout view4;
    @BindView(R.id.view5)
    LinearLayout view5;
    @BindView(R.id.jiangshi)
    RecyclerView jiangshi;


    private List<String> title1;
    private List<Fragment> fragmentList;
    private NewsFragmentAdapter nfa;

    private ZhiboConPersenter zhiboConPersenter = new ZhiboConPersenter(this);
    private int id;
    private String type;

    private String[] titles = {"华南地区较早开展种植诊疗业务规范化的医疗中心", "华南地区较早开展种植诊疗业务规范化的医疗中心", "华南地区较早开展种植诊疗业务规范化的医疗中心"};
    private int[] zhibo_image = {R.drawable.icon_pdf, R.drawable.icon_pdf, R.drawable.icon_shipin};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhibo_content);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        id = intent.getIntExtra("id", 0);
        type = intent.getStringExtra("type");
        switch (type){
            case "zhibo":
                headTitle.setText("直播详情");
                zhiboConPersenter.GetData(String.valueOf(id));
                break;
            case "kecheng":
                headTitle.setText("课程详情");
                zhiboConPersenter.GetKecheng(String.valueOf(id));
                break;
            case "class":
                headTitle.setText("班级详情");
                zhiboConPersenter.GetClass(String.valueOf(id));
                break;
        }


//        View headView = LayoutInflater.from(getBaseContext()).inflate(R.layout.activity_zhibo_content,null);
        //--------直播-----------------
        List<CommonClass> zhiboClasses = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            CommonClass commonClass1 = new CommonClass();
            commonClass1.setTitle(titles[i]);
            commonClass1.setDra_iamge(zhibo_image[i]);
            zhiboClasses.add(commonClass1);
        }
        // 设置布局管理器
        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(getBaseContext(), RecyclerView.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        kejianList.setLayoutManager(linearLayoutManager1);

        ZhiboKejianAdapter zhiboKejianAdapter = new ZhiboKejianAdapter(zhiboClasses, getBaseContext());
        kejianList.setAdapter(zhiboKejianAdapter);
//        zhiboKejianAdapter.setRecycClickOnListener(new RecycClickOnListener() {
//            @Override
//            public void onItemClick(CommonClass commonClass) {
//
//            }
//        });


        title1 = new ArrayList<>();
        fragmentList = new ArrayList<>();


        title1.add("详情");
        title1.add("评论");

        WebFragment webFragment = new WebFragment();
        fragmentList.add(webFragment);

        StudentsFragment webFragment1 = new StudentsFragment();
        fragmentList.add(webFragment1);

        pst.setTabRippleColorResource(R.color.bai);
        nfa = new NewsFragmentAdapter(getSupportFragmentManager(), fragmentList, title1);
        //pst.setTextColor(0xE3E2E3);
        nfa.notifyDataSetChanged();
        vp.setAdapter(nfa);
        pst.setupWithViewPager(vp);
        // 设置布局管理器
        LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(getBaseContext(), RecyclerView.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };

        pst.getTabAt(0).setCustomView(R.layout.tab_layout_text);
        TextView textView = pst.getTabAt(0).getCustomView().findViewById(android.R.id.text1);
        textView.setTextAppearance(getBaseContext(), R.style.TabLayoutTextSize);


        pst.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                View view = tab.getCustomView();
                if (null == view) {
                    tab.setCustomView(R.layout.tab_layout_text);
                }
                TextView textView = tab.getCustomView().findViewById(android.R.id.text1);
                textView.setTextAppearance(getBaseContext(), R.style.TabLayoutTextSize);

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                View view = tab.getCustomView();
                if (null == view) {
                    tab.setCustomView(R.layout.tab_layout_text);
                }
                TextView textView = tab.getCustomView().findViewById(android.R.id.text1);
                textView.setTextAppearance(getBaseContext(), R.style.TabLayoutUnsectedTextSize);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }


    @Override
    public void Toast(String s) {

    }

    @Override
    public void GetData(ZhiboContent zhiboContent) {
        cost.setText(String.valueOf(zhiboContent.getResult().getCost()));
        memberCost.setText("会员价￥" + String.valueOf(zhiboContent.getResult().getMemberCost() + "元"));
        memberCost1.setText("会员价￥" + String.valueOf(zhiboContent.getResult().getMemberCost() + "元"));
        time.setText(zhiboContent.getResult().getStartTime());
        zhibo_title.setText(zhiboContent.getResult().getTitle());
    }

    @Override
    public void GetClass(ClassCon classCon) {
        cost.setText(String.valueOf(classCon.getResult().getCost()));
        memberCost.setText("会员价￥" + String.valueOf(classCon.getResult().getMemberCost() + "元"));
        memberCost1.setText("会员价￥" + String.valueOf(classCon.getResult().getMemberCost() + "元"));
        time.setText(classCon.getResult().getCreateTime().toString());
        zhibo_title.setText(classCon.getResult().getName());
    }

    @Override
    public void GetKecheng(KechengCon kechengCon) {
        cost.setText(String.valueOf(kechengCon.getResult().getCost()));
        memberCost.setText("会员价￥" + String.valueOf(kechengCon.getResult().getMemberCost() + "元"));
        memberCost1.setText("会员价￥" + String.valueOf(kechengCon.getResult().getMemberCost() + "元"));
        time.setText(kechengCon.getResult().getCreateTime());
        zhibo_title.setText(kechengCon.getResult().getName());
    }
}
